home *** CD-ROM | disk | FTP | other *** search
-
- /*
- CLUTLess
-
-
- In some instances it is desireable to store picts stripped of
- CLUTs in order to save some room in the disk. This sample shows
- how to create such picts and how to properly display them back.
-
- SimpleInC.c -- initialization stuff and event loop
- CLUTLess.c -- code that does the creation of the clut less pict;
- shows also how to display the pictures.
-
- */
-
- #include "SimpleInC.h"
-
- short main()
- {
- Rect screenRect;
- Rect dragRect;
- Rect pictRect;
-
- EventRecord myEvent;
- WindowPtr theActiveWindow;
- WindowPtr whichWindow;
- Boolean Result;
-
- /*
- * Initialization traps
- */
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- MaxApplZone();
-
- /* initializes QD procs for our purposes */
- InitProcs(&myProcs);
-
- /* ************************************************************** */
-
- setupMenus();
-
- screenRect = qd.screenBits.bounds;
- SETRECT(&dragRect, 4, 20 + 4, screenRect.right-4, screenRect.bottom-4);
-
- /* here we create a window to display our picture and we allocate a handle
- for the palette we expect to associate with the window.
- */
- myWindow = GetNewCWindow(windowID, nil, (WindowPtr) -1);
- SetPort(myWindow);
-
- // THIS IS THE PLACE WHERE WE GO AND PREPARE THE IMAGE TO BE SAVED AND DISPLAYED
- // Make call to get and set all
- if ( ! ( SetupPictures() )) return 0;
-
- pictRect = (*gOrigPict)->picFrame;
-
- SizeWindow(myWindow, pictRect.right-pictRect.left, pictRect.bottom-pictRect.top, false);
- ShowWindow(myWindow);
-
- if (! gSharedClut ) // the picture did not have a 'clut' with it
- DisableItem(MyMenus[stuffMenu], mClutPict);
- CheckItem(MyMenus[stuffMenu], mUnmodPict, true);
-
- DoneFlag = false;
-
- for ( ;; ) {
- if (DoneFlag) {
- break; /* from main event loop */
- }
- /*
- * Main Event tasks:
- */
- SystemTask();
- theActiveWindow = FrontWindow(); /* Used often, avoid repeated calls */
-
- Result = GetNextEvent(everyEvent, &myEvent);
-
- switch (myEvent.what) {
- case mouseDown:
- switch (FindWindow(myEvent.where, &whichWindow)) {
- case inSysWindow:
- SystemClick(&myEvent, whichWindow);
- break;
-
- case inMenuBar:
- {
- doCommand(MenuSelect(myEvent.where));
- }
- break;
-
- case inDrag:
- DragWindow(whichWindow, myEvent.where, &dragRect);
- break;
-
- case inGrow:
- /* There is no grow box. (Fall through) */
-
- case inContent:
- if (whichWindow != theActiveWindow) {
- SelectWindow(whichWindow);
- }
- default:
- break;
- }/*endsw FindWindow*/
- break;
-
- case keyDown:
- case autoKey:
- if (myWindow == theActiveWindow) {
- if (myEvent.modifiers & cmdKey) {
- doCommand(MenuKey(myEvent.message & charCodeMask));
- }
- }
- break;
-
- case activateEvt:
- if ((WindowPtr) myEvent.message == myWindow) {
- if (myEvent.modifiers & activeFlag) {
- /* TEActivate(TextH); */
- DisableItem(MyMenus[editMenu], undoCommand);
- }
- }
- break;
-
- case updateEvt:
-
- if ((WindowPtr) myEvent.message == myWindow) {
- BeginUpdate(myWindow);
- SetPort(myWindow);
- DrawPicture(gCurrPict, &((*gCurrPict) -> picFrame)); /* draw the thing */
- EndUpdate(myWindow);
- }
- default:
- break;
-
- }/*endsw myEvent.what*/
-
- }/*endfor Main Event loop*/
- return 0; /* Return from main() to allow C runtime cleanup */
- }
-
- void setupMenus(void)
- {
- extern MenuHandle MyMenus[];
- register MenuHandle *pMenu;
-
- MyMenus[appleMenu] = GetMenu(appleID);
- AddResMenu(MyMenus[appleMenu], (ResType) 'DRVR');
- /*
- * Now the menus.
- */
-
- MyMenus[fileMenu] = GetMenu(fileID);
- MyMenus[editMenu] = GetMenu(editID);
- MyMenus[stuffMenu] = GetMenu(stuffID);
-
- for (pMenu = &MyMenus[0]; pMenu < &MyMenus[menuCount]; ++pMenu) {
- InsertMenu(*pMenu, 0);
- }
-
- DrawMenuBar();
-
- return;
- }
-
- void showAboutMeDialog(void)
- {
- GrafPtr savePort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit;
-
- GetPort(&savePort);
- theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
- SetPort(theDialog);
-
- GetDItem(theDialog, authorItem, &itemType, &itemHdl, &itemRect);
- SetIText(itemHdl, "\pGuillermo A. Ortiz, MacDTS");
- GetDItem(theDialog, languageItem, &itemType, &itemHdl, &itemRect);
- SetIText(itemHdl, "\pC");
-
- do {
- ModalDialog(nil, &itemHit);
- } while (itemHit != okButton);
-
- CloseDialog(theDialog);
-
- SetPort(savePort);
- return;
- }
- /*
- * Process mouse clicks in menu bar
- */
-
- Boolean hilited = false;
-
- void doCommand(long mResult)
- {
- long theMenu, theItem;
- unsigned char daName[256];
- GrafPtr savePort;
- extern MenuHandle MyMenus[];
- extern Boolean DoneFlag;
- extern void showAboutMeDialog();
-
- theItem = LOWORD(mResult);
- theMenu = HIWORD(mResult); /* This is the resource ID */
-
- switch (theMenu) {
- case appleID:
- if (theItem == aboutMeCommand) {
- showAboutMeDialog();
- } else {
- GetItem(MyMenus[appleMenu], theItem, daName);
- GetPort(&savePort);
- (void) OpenDeskAcc(daName);
- SetPort(savePort);
- }
- break;
-
- case fileID:
- switch (theItem) {
- case printCommand:
- break;
- case pageCommand:
- break;
- case quitCommand:
- DoneFlag = true; /* Request exit */
- break;
- default:
- break;
- }
- break;
-
- case editID:
- /*
- * If this is for a 'standard' edit item,
- * run it through SystemEdit first.
- * SystemEdit will return FALSE if it's not a system window.
- */
- if ((theItem <= clearCommand) && SystemEdit(theItem-1)) {
- break;
- }
- switch (theItem) {
- case undoCommand:
- case cutCommand:
- case copyCommand:
- case pasteCommand:
- case clearCommand:
- default:
- break;
- } /*endsw theItem*/
- break;
-
- case stuffID:
- /* uncheck all the items to begin with */
- CheckItem(MyMenus[stuffMenu], mUnmodPict, false);
- CheckItem(MyMenus[stuffMenu], mNoClutPict, false);
- CheckItem(MyMenus[stuffMenu], mClutPict, false);
-
- switch (theItem) {
- case mUnmodPict:
- gCurrPict = gOrigPict; /* draw of original pict */
- InvalRect(&(myWindow->portRect));
- myWindow -> grafProcs = nil;
- CheckItem(MyMenus[stuffMenu], mUnmodPict, true);
- break;
- case mNoClutPict:
- gCurrPict = gModPict; /* draw of clut less pict */
- InvalRect(&(myWindow->portRect));
- myWindow -> grafProcs = nil;
- CheckItem(MyMenus[stuffMenu], mNoClutPict, true);
- break;
- case mClutPict:
- gCurrPict = gModPict; /* draw of clut less pict */
- InvalRect(&(myWindow->portRect));
- /* but use the proc to add color table to it */
- myWindow -> grafProcs = (QDProcsPtr)(& myProcs);
- CheckItem(MyMenus[stuffMenu], mClutPict, true);
- break;
- default:
- break;
- }
- break;
-
- default:
- break;
-
- }/*endsw theMenu*/
-
- HiliteMenu(0);
-
- return;
- }
-
-